//
//  ProductDetailController.m
//  FinancialProduct
//
//  Created by Stella on 2017/9/9.
//  Copyright © 2017年 maq. All rights reserved.
//
#import "MyAccountCell.h"
#import "UIColor+NN.h"
#import "LineView.h"
#import "HandleNetProduct.h"
#import "CKPuslichTool.h"
#import "UserModel.h"
#import "MakeAppointmentController.h"
#import "SVProgressHUD.h"
#import "myWebViewController.h"
#import "ProductDetailController.h"
#import "TKAlertCenter.h"


@interface ProductDetailController ()
@property (weak, nonatomic) IBOutlet UIView *redView;
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UILabel *abcMode;
@property (weak, nonatomic) IBOutlet UILabel *topLeft;
@property (weak, nonatomic) IBOutlet UILabel *topRight;
@property (weak, nonatomic) IBOutlet UILabel *openTime;
@property (weak, nonatomic) IBOutlet UILabel *closeTime;
@property (weak, nonatomic) IBOutlet UILabel *hasTime;
@property (weak, nonatomic) IBOutlet UILabel *dateLabe;
@property (weak, nonatomic) IBOutlet UIButton *makeBt;

@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UIView *bottomView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableToBottom;

@end

@implementation ProductDetailController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    UIViewSetRadius(self.redView, 60, 5, [UIColor colorWithHexString:@"F0ABAB"]);
    UIViewSetRadius(_makeBt, 25, 0, nil);
    LineView *lineView=[[LineView alloc] initWithFrame:CGRectMake(0, 0, 120, 120) lineCount:4];
    [self.bgView addSubview:lineView];
    [self initMyView];
    self.bottomView.backgroundColor = [UIColor clearColor];
    if ([[UserModel getUser].Accountstatus intValue]==2) {
        //判断临时客户，去预约理财师
        self.tableToBottom.constant = 80;
        self.bottomView.hidden = NO;
    }else{
        self.tableToBottom.constant = 0;
        self.bottomView.hidden = YES;
    }
}


- (IBAction)makePoint:(id)sender {
    MakeAppointmentController *make = (MakeAppointmentController *)[CKPuslichTool getViewControllerFromStroyBoard:@"Product" viewID:@"MakeAppointmentController"];
    [self.navigationController pushViewController:make animated:YES];
}

//

-(void)initMyView{
    self.dateLabe.text=@"产品成立日";
    if ([self.productModel.ProductType isEqualToString:@"A"]) {
        self.dateLabe.text=@"产品开放日";
    }
    self.name.text=_productModel.SubProductName;
    self.abcMode.text=[NSString stringWithFormat:@"%@类资产",_productModel.ABCModel];
    self.topLeft.text=_productModel.ExpectedRate;
    self.topRight.text=_productModel.SaleAmount;
    self.openTime.text=_productModel.PurchaseOpenDay;
    self.closeTime.text=[NSString stringWithFormat:@"预约截止日期：%@",_productModel.ClosingDate];
    self.hasTime.text=_productModel.ProductPeriod;
    

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Table view data source
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50
    ;
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 1;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    

    return 3;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    MyAccountCell *cell=[tableView dequeueReusableCellWithIdentifier:@"MyAccountCell" forIndexPath:indexPath];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.accessoryType=UITableViewCellAccessoryNone;
    if (indexPath.row==0) {
        cell.NameLabel.text=@"基本信息";
    }else if (indexPath.row==1){
        cell.NameLabel.text=@"个人认购提示";
    }else{
        cell.NameLabel.text=@"机构认购提示";
    }
    
    return cell;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
       
        case 0://基本信息
        {

            [self getURLWith:@"EssentialInformation"];
        }
            break;
        case 1://个人认购提示
        {
            
            [self getURLWith:@"Personage"];
        }
            break;
        case 2://机构认购提示
        {
            [self getURLWith:@"InstitutionalSubscription"];
        }
            break;
            
        default:
            break;
    }

 
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];

    
}
-(void)getURLWith:(NSString *)type{
    NSLog(@"self.productModel.SubProductID==%@",self.productModel.SubProductID);
    NSDictionary *params=@{@"AAAMethodName":type,
//                           @"SubProductId":self.productId,
                           @"SubProductId":self.productId};
    [HandleNetProduct getDetailForParams:params Success:^(NSDictionary *data) {
        NSString *paths=data[@"Path"];
   
        myWebViewController *vc=(myWebViewController *)[CKPuslichTool getViewControllerFromStroyBoard:@"Setting" viewID:@"myWebViewController"];
        if ([type isEqualToString:@"EssentialInformation"]) {
            vc.title=@"基本信息";
        }else if ([type isEqualToString:@"Personage"]) {
            vc.title=@"个人认购提示";
        }else{
            vc.title=@"机构认购提示";
        }
        vc.urlString=paths;
        
        
        [self.navigationController pushViewController:vc animated:YES];
        

    } Failure:^(NSString *errorInfo) {
    
        [[TKAlertCenter defaultCenter]postAlertWithMessage:errorInfo];
        
    }];

}

@end
